// app.js
const {apikey} = require("./utils/config")
App({
  globalData:{
    currentCity:""
  },
  onLaunch:function(){
    wx.getLocation({
      type: 'wgs84',
      success: (res)=>{
        var {latitude,longitude} = res;
        // console.log(res);
        var url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${apikey}&get_poi=1`
        wx.request({
          url,
          data: {},
          header: {'content-type':'application/json'},
          method: 'GET',
          dataType: 'json',
          responseType: 'text',
          success: (res)=>{
            // console.log(res);
            
            if(this.callback){
              var city = res.data.result.address_component.city;
              wx.setStorageSync('locationCity', city);
              this.globalData.currentCity = city;
              this.callback()
            }
          },
        });
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  }
})
